<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Register extends CI_Controller {

    public function __construct() {
      parent::__construct();
      
      // Load languge helper
      $this->load->helper('language');
      // Set language
      //if( ! $this->session->userdata('lang') ) // UVEK ES (Spanski)
      {
        $this->session->set_userdata('lang','de');
      }
      // Load language file
      $this->lang->load($this->session->userdata('lang'));

      // Load Favorites library
      $this->load->library('modules');
      
      $this->load->model('users_mod');
      $this->load->model('cities_mod');
    }
	/**
	 *
	 */
	public function index()
	{       
        $data['title'] = lang('register_title');
        $data['keywords'] = lang('register_keywords');
        $data['description'] = lang('register_description');
        
        $data['user'] = $this->input->post('user');
        //$data['states'] = $this->users_mod->getStatesList();
        $data['cities'] = $this->cities_mod->getCitiesList();
        $data['menu_active'] = "home";
        $data['contents']  = "register/home";   
		$this->load->view('template/main',$data);
	}
    
    
    public function forgot_password()
    {
        $data['title'] = lang('profile_title');
        $data['keywords'] = lang('profile_keywords');
        $data['description'] = lang('profile_description');
        $data['menu_active'] = "home";
        $data['contents']  = "register/forgot_password";   
		$this->load->view('template/main',$data);
    }
    
    public function register_success()
    {
        $id = $this->input->get('id');
        $data['title'] = lang('profile_title');
        $data['keywords'] = lang('profile_keywords');
        $data['description'] = lang('profile_description');
        $data['user'] = $this->users_mod->getRegisterUserData($id);
        $data['menu_active'] = "home";
        $data['contents']  = "register/register_success";   
		$this->load->view('template/main',$data);
    }
    
    public function confirm_registration()
    {
        $id = $this->input->get('a');
        $md5mail = $this->input->get('b');
        
        $data['title'] = lang('profile_title');
        $data['keywords'] = lang('profile_keywords');
        $data['description'] = lang('profile_description');
        $user = $this->users_mod->getRegisterUserData($id);
        if( $md5mail == md5($user->email) )
        {
          $this->users_mod->userConfirmRegistration($id);
          $data['user'] = $user;
          $data['menu_active'] = "home";
          $data['contents']  = "register/register_confirm";
          $this->load->view('template/main',$data);   
        }
        else
          redirect(base_url());
		
    }
    
    /**
     *  AJAX
     */
    public function register_user()
    {
      try{
        $user = $this->input->post('user');
        
        if( $id = $this->users_mod->register($user) )
        {
            $response = array(
                          'ind' => 1,
                          'msg' => "",
                          'redirect_url' => base_url()."register/register-success.htm?id=".$id
                      );
        }
        else
        {
            $response = array(
                          'ind' => 0,
                          'msg' => "",
                          'redirect_url' => base_url()."register.htm"
                      );
        }
      }
      catch (Exception $e) {

          $response = array(
              'ind' => 0,
              'msg' => lang('following_errors').': <br />' . $e->getMessage(),
              'num_online' => 0
          );
      }
      echo json_encode($response); 
    }
    
} // end class
/* End of file register.php */
/* Location: ./application/controllers/register.php */